libxl: fix fd check in libxl__spawn_local_dm
authorRoger Pau Monne <roger.pau@citrix.com>
Fri, 22 Nov 2013 11:54:08 +0000 (12:54 +0100)
committerIan Campbell <ian.campbell@citrix.com>
Tue, 26 Nov 2013 10:55:34 +0000 (10:55 +0000)
Checking the logfile_w fd for -1 on failure is no longer true, because
libxl__create_qemu_logfile will now return ERROR_FAIL on failure which
is -3.

While there also add an error check for opening /dev/null.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
Cc: Ian Jackson <Ian.Jackson@eu.citrix.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
tools/libxl/libxl_dm.c

index 292e351787670c67ffd1965b9345d416354c386f..be39a62ff7c56355079a376ac8fb49bbe7c7e558 100644 (file)
@@ -1228,6 +1228,11 @@ void libxl__spawn_local_dm(libxl__egc *egc, libxl__dm_spawn_state *dmss)
         goto out;
     }
     null = open("/dev/null", O_RDONLY);
+    if (null < 0) {
+        LOGE(ERROR, "unable to open /dev/null");
+        rc = ERROR_FAIL;
+        goto out_close;
+    }
 
     const char *dom_path = libxl__xs_get_dompath(gc, domid);
     spawn->pidpath = GCSPRINTF("%s/%s", dom_path, "image/device-model-pid");
@@ -1275,8 +1280,8 @@ retry_transaction:
     rc = 0;
 
 out_close:
-    if (null != -1) close(null);
-    if (logfile_w != -1) close(logfile_w);
+    if (null >= 0) close(null);
+    if (logfile_w >= 0) close(logfile_w);
 out:
     if (rc)
         device_model_spawn_outcome(egc, dmss, rc);